package hasthi.wsdm.systemhandle;

import java.util.List;

import javax.xml.namespace.QName;

import hasthi.common.HasthiException;
import hasthi.common.HasthiException.FaultCode;
import hasthi.common.constants.WSDMConstants;
import hasthi.wsdm.ManagedSystemHandle;

public class SystemHandleVerifier {

    
    public static void verify(ManagedSystemHandle handle) throws HasthiException{
        verifyNotNull(handle.getResourceName(),"ResourceName");
        verifyNotNull(handle.getDescription(),"Description");
        verifyNotNull(handle.getCurrentSystemState(),"System State");
        verifyNotNull(handle.getLastStateTransition(),"LastStateTransition");
        verifyNotNull(handle.getSystemEndPoint(),"SystemEndPoint");
        
        List<QName> configNames = handle.getSupportedConfigurationNames();
        if(configNames == null){
            throw new HasthiException("ManagedSystemHandle must define a configuration called "
                    +WSDMConstants.MANAGEMENT_EVENT_SINK_PARAM,FaultCode.InitalizationError);
        }
        for(QName name:configNames){
            verifyNotNull(handle.getConfiguration(name),name.toString());
        }
        
        List<QName> matricNames = handle.getSupportedMatrics();
        if(matricNames != null){
            for(QName name:matricNames){
                verifyNotNull(handle.getMatric(name),name.toString());
            }
        }
    }
    
    public static void verifyNotNull(Object value, String propertyName) throws HasthiException{
        if(value == null){
            throw new HasthiException(propertyName + " must not be null",FaultCode.InitalizationError);
        }
    }
    
}
